#!/usr/bin/env python2 # -*- coding: utf-8 -*- """ This experiment was created using PsychoPy2 Experiment Builder (v1.83.04), Wed 08 Feb 2017 11:41:38 AM EST If you publish work using this script please cite the relevant PsychoPy publications Peirce, JW (2007) PsychoPy - Psychophysics software in Python. Journal of Neuroscience Methods, 162(1-2), 8-13. Peirce, JW (2009) Generating stimuli for neuroscience using PsychoPy. Frontiers in Neuroinformatics, 2:10. doi: 10.3389/neuro.11.010.2008 """ from __future__ import division # so that 1/3=0.333 instead of 1/3=0 from psychopy import locale_setup, visual, core, data, event, logging, sound, gui from psychopy.constants import * # things like STARTED, FINISHED import numpy as np # whole numpy lib is available, prepend 'np.' from numpy import sin, cos, tan, log, log10, pi, average, sqrt, std, deg2rad, rad2deg, linspace, asarray from numpy.random import random, randint, normal, shuffle import os # handy system and path functions import sys # to get file system encoding # Ensure that relative paths start from the same directory as this script _thisDir = os.path.dirname(os.path.abspath(__file__)).decode(sys.getfilesystemencoding()) os.chdir(_thisDir) # Store info about the experiment session expName = 'the_present_withcredits_play' # from the Builder filename that created this script expInfo = {'participant':'', 'session':'001'} dlg = gui.DlgFromDict(dictionary=expInfo, title=expName) if dlg.OK == False: core.quit() # user pressed cancel expInfo['date'] = data.getDateStr() # add a simple timestamp expInfo['expName'] = expName # Data file name stem = absolute path + name; later add .psyexp, .csv, .log, etc filename = _thisDir + os.sep + 'data/%s_%s_%s' %(expInfo['participant'], expName, expInfo['date']) # An ExperimentHandler isn't essential but helps with data saving thisExp = data.ExperimentHandler(name=expName, version='', extraInfo=expInfo, runtimeInfo=None, originPath=u'/home/user/Desktop/HBN/the_present_withcredits_play.psyexp', savePickle=True, saveWideText=True, dataFileName=filename) #save a log file for detail verbose info logFile = logging.LogFile(filename+'.log', level=logging.EXP) logging.console.setLevel(logging.WARNING) # this outputs to the screen, not a file endExpNow = False # flag for 'escape' or other condition => quit the exp # Start Code - component code to be run before the window creation # Setup the Window win = visual.Window(size=(1680, 1050), fullscr=True, screen=0, allowGUI=False, allowStencil=False, monitor='testMonitor', color=[0,0,0], colorSpace='rgb', blendMode='avg', useFBO=True, ) # store frame rate of monitor if we can measure it successfully expInfo['frameRate']=win.getActualFrameRate() if expInfo['frameRate']!=None: frameDur = 1.0/round(expInfo['frameRate']) else: frameDur = 1.0/60.0 # couldn't get a reliable measure so guess # Initialize components for Routine "trial" trialClock = core.Clock() ISI = core.StaticPeriod(win=win, screenHz=expInfo['frameRate'], name='ISI') Intro = visual.TextStim(win=win, ori=0, name='Intro', text='In this section you will see a movie', font='Arial', pos=[0, 0], height=0.1, wrapWidth=None, color='Black', colorSpace='rgb', opacity=1, depth=-1.0) # Initialize components for Routine "wait_for_trigger" wait_for_triggerClock = core.Clock() TriggerWait = visual.TextStim(win=win, ori=0, name='TriggerWait', text='The Movie is about to start', font='Arial', pos=[0, 0], height=0.1, wrapWidth=None, color='black', colorSpace='rgb', opacity=1, depth=0.0) # Initialize components for Routine "movie_play" movie_playClock = core.Clock() movie = visual.MovieStim2(win=win, name='movie', noAudio = False, filename='the_present.mp4', ori=0, pos=[0, 0], opacity=1, size=[1000,600], depth=0.0, ) # Create some handy timers globalClock = core.Clock() # to track the time since experiment started routineTimer = core.CountdownTimer() # to track time remaining of each (non-slip) routine #------Prepare to start Routine "trial"------- t = 0 trialClock.reset() # clock frameN = -1 routineTimer.add(3.000000) # update component parameters for each repeat # keep track of which components have finished trialComponents = [] trialComponents.append(ISI) trialComponents.append(Intro) for thisComponent in trialComponents: if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED #-------Start Routine "trial"------- continueRoutine = True while continueRoutine and routineTimer.getTime() > 0: # get current time t = trialClock.getTime() frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *Intro* updates if t >= 0.0 and Intro.status == NOT_STARTED: # keep track of start time/frame for later Intro.tStart = t # underestimates by a little under one frame Intro.frameNStart = frameN # exact frame index Intro.setAutoDraw(True) if Intro.status == STARTED and t >= (0.0 + (3.0-win.monitorFramePeriod*0.75)): #most of one frame period left Intro.setAutoDraw(False) # *ISI* period if t >= 0.0 and ISI.status == NOT_STARTED: # keep track of start time/frame for later ISI.tStart = t # underestimates by a little under one frame ISI.frameNStart = frameN # exact frame index ISI.start(3.0) elif ISI.status == STARTED: #one frame should pass before updating params and completing ISI.complete() #finish the static period # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in trialComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # check for quit (the Esc key) if endExpNow or event.getKeys(keyList=["escape"]): core.quit() # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() #-------Ending Routine "trial"------- for thisComponent in trialComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) #------Prepare to start Routine "wait_for_trigger"------- t = 0 wait_for_triggerClock.reset() # clock frameN = -1 # update component parameters for each repeat key_resp_2 = event.BuilderKeyResponse() # create an object of type KeyResponse key_resp_2.status = NOT_STARTED # keep track of which components have finished wait_for_triggerComponents = [] wait_for_triggerComponents.append(TriggerWait) wait_for_triggerComponents.append(key_resp_2) for thisComponent in wait_for_triggerComponents: if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED #-------Start Routine "wait_for_trigger"------- continueRoutine = True while continueRoutine: # get current time t = wait_for_triggerClock.getTime() frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *TriggerWait* updates if t >= 0.0 and TriggerWait.status == NOT_STARTED: # keep track of start time/frame for later TriggerWait.tStart = t # underestimates by a little under one frame TriggerWait.frameNStart = frameN # exact frame index TriggerWait.setAutoDraw(True) # *key_resp_2* updates if t >= 0.0 and key_resp_2.status == NOT_STARTED: # keep track of start time/frame for later key_resp_2.tStart = t # underestimates by a little under one frame key_resp_2.frameNStart = frameN # exact frame index key_resp_2.status = STARTED # keyboard checking is just starting win.callOnFlip(key_resp_2.clock.reset) # t=0 on next screen flip event.clearEvents(eventType='keyboard') if key_resp_2.status == STARTED: theseKeys = event.getKeys(keyList=['5']) # check for quit: if "escape" in theseKeys: endExpNow = True if len(theseKeys) > 0: # at least one key was pressed key_resp_2.keys.extend(theseKeys) # storing all keys key_resp_2.rt.append(key_resp_2.clock.getTime()) # a response ends the routine continueRoutine = False # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in wait_for_triggerComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # check for quit (the Esc key) if endExpNow or event.getKeys(keyList=["escape"]): core.quit() # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() #-------Ending Routine "wait_for_trigger"------- for thisComponent in wait_for_triggerComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) # check responses if key_resp_2.keys in ['', [], None]: # No response was made key_resp_2.keys=None # store data for thisExp (ExperimentHandler) thisExp.addData('key_resp_2.keys',key_resp_2.keys) if key_resp_2.keys != None: # we had a response thisExp.addData('key_resp_2.rt', key_resp_2.rt) thisExp.nextEntry() # the Routine "wait_for_trigger" was not non-slip safe, so reset the non-slip timer routineTimer.reset() #------Prepare to start Routine "movie_play"------- t = 0 movie_playClock.reset() # clock frameN = -1 routineTimer.add(203.200000) # update component parameters for each repeat # keep track of which components have finished movie_playComponents = [] movie_playComponents.append(movie) for thisComponent in movie_playComponents: if hasattr(thisComponent, 'status'): thisComponent.status = NOT_STARTED #-------Start Routine "movie_play"------- continueRoutine = True while continueRoutine and routineTimer.getTime() > 0: # get current time t = movie_playClock.getTime() frameN = frameN + 1 # number of completed frames (so 0 is the first frame) # update/draw components on each frame # *movie* updates if t >= 0.0 and movie.status == NOT_STARTED: # keep track of start time/frame for later movie.tStart = t # underestimates by a little under one frame movie.frameNStart = frameN # exact frame index movie.setAutoDraw(True) if movie.status == STARTED and t >= (0.0 + (203.2-win.monitorFramePeriod*0.75)): #most of one frame period left movie.setAutoDraw(False) if movie.status == FINISHED: # force-end the routine continueRoutine = False # check if all components have finished if not continueRoutine: # a component has requested a forced-end of Routine break continueRoutine = False # will revert to True if at least one component still running for thisComponent in movie_playComponents: if hasattr(thisComponent, "status") and thisComponent.status != FINISHED: continueRoutine = True break # at least one component has not yet finished # check for quit (the Esc key) if endExpNow or event.getKeys(keyList=["escape"]): core.quit() # refresh the screen if continueRoutine: # don't flip if this routine is over or we'll get a blank screen win.flip() #-------Ending Routine "movie_play"------- for thisComponent in movie_playComponents: if hasattr(thisComponent, "setAutoDraw"): thisComponent.setAutoDraw(False) # these shouldn't be strictly necessary (should auto-save) thisExp.saveAsWideText(filename+'.csv') thisExp.saveAsPickle(filename) logging.flush() # make sure everything is closed down thisExp.abort() # or data files will save again on exit win.close() core.quit()